package com.haixiaoke.saas.apartment.service.impl;

import cn.hutool.core.util.StrUtil;
import com.haixiaoke.saas.common.utils.DateUtils;
import com.haixiaoke.saas.apartment.domain.BusinessCircle;
import com.haixiaoke.saas.apartment.mapper.BusinessCircleMapper;
import com.haixiaoke.saas.apartment.service.IBusinessCircleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商业区Service业务层处理
 *
 * @author xiaolong
 * @date 2023-10-25
 */
@Service
public class BusinessCircleServiceImpl implements IBusinessCircleService {
    @Autowired
    private BusinessCircleMapper businessCircleMapper;

    /**
     * 查询商业区
     *
     * @param businessCircleId 商业区主键
     * @return 商业区
     */
    @Override
    public BusinessCircle selectBusinessCircleByBusinessCircleId(Long businessCircleId) {
        return businessCircleMapper.selectBusinessCircleByBusinessCircleId(businessCircleId);
    }

    /**
     * 查询商业区列表
     *
     * @param businessCircle 商业区
     * @return 商业区
     */
    @Override
    public List<BusinessCircle> selectBusinessCircleList(BusinessCircle businessCircle) {
        return businessCircleMapper.selectBusinessCircleList(businessCircle);
    }

    /**
     * 新增商业区
     *
     * @param businessCircle 商业区
     * @return 结果
     */
    @Override
    public int insertBusinessCircle(BusinessCircle businessCircle) {
        businessCircle.setCreateTime(DateUtils.getNowDate());
        return businessCircleMapper.insertBusinessCircle(businessCircle);
    }

    /**
     * 修改商业区
     *
     * @param businessCircle 商业区
     * @return 结果
     */
    @Override
    public int updateBusinessCircle(BusinessCircle businessCircle) {
        businessCircle.setUpdateTime(DateUtils.getNowDate());
        return businessCircleMapper.updateBusinessCircle(businessCircle);
    }

    /**
     * 批量删除商业区
     *
     * @param businessCircleIds 需要删除的商业区主键
     * @return 结果
     */
    @Override
    public int deleteBusinessCircleByBusinessCircleIds(Long[] businessCircleIds) {
        return businessCircleMapper.deleteBusinessCircleByBusinessCircleIds(businessCircleIds);
    }

    /**
     * 删除商业区信息
     *
     * @param businessCircleId 商业区主键
     * @return 结果
     */
    @Override
    public int deleteBusinessCircleByBusinessCircleId(Long businessCircleId) {
        return businessCircleMapper.deleteBusinessCircleByBusinessCircleId(businessCircleId);
    }

    @Override
    public String selectBusinessCircleFullNamesByIdIn(List<Long> businessCircleIdList) {
        List<BusinessCircle> businessCircles = businessCircleMapper.selectBusinessCircleByBusinessCircleIdIn(businessCircleIdList);
        StringBuilder businessCircleFullName = new StringBuilder("");

        if (!businessCircles.isEmpty()) {
            for (BusinessCircle businessCircle : businessCircles) {
                String provinceName = businessCircle.getProvinceName();
                String cityName = businessCircle.getCityName();
                String attractionsName = businessCircle.getBusinessCircleName();
                businessCircleFullName.append(provinceName).append(cityName).append(attractionsName).append(",");
            }
        }
        if (StrUtil.isNotBlank(businessCircleFullName)){
            businessCircleFullName.deleteCharAt(businessCircleFullName.lastIndexOf(","));
        }
        return businessCircleFullName.toString();
    }
}
